#ifndef SES_TIMER_H_
#define SES_TIMER_H_

#include <avr/io.h>
#include <util/delay.h>
#include <stdint.h>
#include "ses_common.h"



/*
 * Timer that triggers interrupts every 1 ms.
 * If an interrupt is triggered, the current task's context is saved, the next
 * task's context is restored, and the next task is executed where it stopped.
 */



/* Size of stack for each task. */
#define THREAD_STACK_SIZE	256



/* Type of function pointer used as timer callback. */
typedef void (*pTimerCallback)(void);

/* Current stack pointer. */
volatile void *pstack ;

/* Type struct for tasks with stack, stack pointer, and pointer to next task. */
typedef struct task_t {
	uint8_t stack[THREAD_STACK_SIZE];
	void *pstack;
	struct task_t *next;
} ptask;



/* Initializes hardware timer 2 of MCU.
 * Timer callback is executed each millisecond.
 *
 * @param cb	valid pointer to callback function
 */
void timer2_init(pTimerCallback cb_task);



#endif /* SES_TIMER_H_ */
